﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Automobile.service.BLL;
using Automobile.service.Model;
using Automobile.service.Common;

namespace Automobile.service.UI
{
    public partial class member_list : System.Web.UI.Page
    {
        MemberCardBLL bll = new MemberCardBLL();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                memLoad();
                
            }
        }

        protected void memLoad()
        {

            string fitstdate = this.datemin.Value;
            string lastdate = this.datemax.Value;
            String MemberCard_owner = this.MemberCard_owner.Value;
            this.AspNetPager1.PageSize = 3;
            Label.Text = bll.CountMemberCard(fitstdate,lastdate, MemberCard_owner).ToString();
            this.AspNetPager1.RecordCount = bll.CountMemberCard(fitstdate, lastdate, MemberCard_owner);
            Repeater1.DataSource = bll.SearchMemberCard(AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize, fitstdate, lastdate, MemberCard_owner);
            Repeater1.DataBind();
        }

        protected void Unnamed1_PageChanged(object sender, EventArgs e)
        {
            memLoad();
        }

        protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            JournalBLL jbll = new JournalBLL();
            string ename = e.CommandName;
            string id = e.CommandArgument.ToString();
            switch(ename)
            {
                case "del":
                    if(bll.DelMemberCard(id)>0)
                    {
                        jbll.AddJourna_DelMemberCard(Convert.ToInt32(Session["empid"]),id);
                        Response.Write("<script>alert('删除成功');</script>");
                        memLoad();
                    }
                    else
                    {
                        Response.Write("<script>alert('服务器忙');</script>");
                    }
                    break;
                case  "upt":
                    Response.Redirect("Supplier_Upt.aspx?id=" + id);
                    break;
            }
        }

        protected void Unnamed_ServerClick(object sender, EventArgs e)
        {
            memLoad();
        }
    }
}